from django.conf import settings
from django.views.generic import TemplateView

from oracle.base import baseview


class ParametersHandle(baseview.BaseMixin, TemplateView):
    """
    api方式返回参数信息
    """
    template_name = 'oracle/login.html'

    def post(self, request, *args, **kwargs):
        data = dict()
        status = "success"
        force_external_render = "external"
        # TODO 验证登录
        # 获取想要获得什么参数
        params = request.POST.get("params")
        if params:
            params = params.split(",")
            for param in params:
                if hasattr(self, param):
                    data[param] = getattr(self, param)()
        return baseview.render_handler(request, status, data=data, render=force_external_render)

    def menu(self):
        if hasattr(self.request, 'o_menu'):
            return self.request.o_menu
        else:
            return self.request.session[settings.MENU_SESSION_KEY]

    def breadcrumbs(self):
        if hasattr(self.request, 'o_breadcrumbs'):
            return self.request.o_breadcrumbs
        else:
            return [{"title": "首页", "url": "/", "class": None, }, ]
